package TUILayer;
import java.util.Scanner;
import ControlLayer.DVDCtr;
/**
 * User interface to the DVD controller
 * @author(kbh)
 * @version(2005.03.31)
 * (FEN): 2006.02.24: Comments translated into English
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 * (KBH): 2008.10.24: dvdmenu changed to If                   
 */

public class DvdUI
{
    private DVDCtr dvdCtr;//DVD UI must know the DVD controller 
    
    public DvdUI()
    {
        dvdCtr = new DVDCtr();
    }
    
    public void start()
    {
        dvdMenu();
    }
    
    private void dvdMenu()
    {   
        boolean exit = false;
        while(!exit)
        {
            //show menu and return the user's choise
            int choice =   writeDVDMenu();
            if (choice == 1)
            {
                 showDvdInfo();
            }
            else
            {
                if(choice == 2)
                {
                    createDvd();
                }
                else
                {
                    if(choice == 3)
                    {
                        updateDvd();
                    }
                    else
                    {
                        if(choice == 4)
                        {
                            deleteDvd();
                        }
                        else
                        {
                            if(choice == 5)
                            {
                                listAllDvds();
                            }
                            else
                            {
                                exit = true;
                            }//end else
                        }
                    }//end else
                }//end else
            }//end else
            
        }//end while
    }
    
    private int writeDVDMenu()
    {
           // creates an object keyboard to read data from the keyboard
            Scanner keyboard = new Scanner(System.in);
            System.out.println("\f *** DVD Menu ***");
            System.out.println(" (1) Show DVD information");
            System.out.println(" (2) Create DVD");
            System.out.println(" (3) Update DVD info");
            System.out.println(" (4) Delete DVD");
            System.out.println(" (5) Show current DVD list");
            System.out.println(" (6) Return");
            System.out.print("\n Make your choice: ");
            
            int choice = keyboard.nextInt();
            return choice;
    }
    
    private int inputDvdId()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD Id number: ");
        int no = keyboard.nextInt();
        return no;
    }
        
    private String inputTitle()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD title: " );
        String title = keyboard.nextLine();
        return title;
    }
    
    private String inputAquireDate()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD aquire date: " );
        String date = keyboard.nextLine();
        return date;
    }
    
    private double inputPrice()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type the dvd price: ");
        double no = keyboard.nextDouble();
        return no;
    }

    private void showDvdInfo()
    {
        int dvdId = inputDvdId();
        dvdCtr.printInfo(dvdId);
    }

    private void createDvd()
    {
        String title = inputTitle();
        String date = inputAquireDate();
        double price = inputPrice();
        dvdCtr.addDVD(title, date, price);
    }
    
    private void updateDvd()
    {
    boolean exit = false;
    while(!exit)
    {
        //show menu and return the user's choise
        int choice =   writeDVDMenu();
            if (choice == 1)
            {
                 changeTitle();
            }
            else
            {
                if(choice == 2)
                {
                    
                }
                else
                {
                    if(choice == 3)
                    {
                        
                    }
                    else
                    {
                        
                    }
                }
            }
        }
    }                
    
    private int updateDvdMenu()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\f *** Update dvd menu ***");
        System.out.println(" (1) Update title");
        System.out.println(" (2) Update aquire date");
        System.out.println(" (3) Update aquire price");
        System.out.println(" (4) Return");
        System.out.print("\n Make your choice: ");
            
        int choice = keyboard.nextInt();
        return choice;
    }
    
    private void deleteDvd()
    {
        int dvdId = inputDvdId();
        dvdCtr.deleteDVD(dvdId);
    }
    
    private void listAllDvds()
    {
        dvdCtr.printAllDvdInfo();
    }
    
    private void changeTitle()
    {
        dvdCtr.changeTitle(inputDvdId(), inputTitle());
    }
    
    private void changeAquireDate()
    {
        dvdCtr.changeAquireDate(inputDvdId(), inputAquireDate());
    }
    
    private void changeAquirePrice()
    {
        dvdCtr.changeAquirePrice(inputDvdId(), inputPrice());
    }
}